/**
* \file DGVImageVTK.h
*
* \brief This file defines a class for displaying Images using VTK Image Viewer2.
* \author Shekhar S. Chandra, 2008-2009
*
* This file is part of DGV Library.
*
* DGV is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DGV is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DGV.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DGVIMAGEVTK_H
#define DGVIMAGEVTK_H

#include <QtGui/QtGui>

#include "QVTKWidget.h" //For base class
#include "vtkSmartPointer.h"
#include "vtkImageViewer2.h" //For image display from VTK5+
#include "vtkImageData.h"
#include "vtkImageMagnify.h"
#include "vtkImagePermute.h"

#include "DGVBlitzArrayCasterVTK.h"
#include "DGVConsole.h"
#include "DGVTableVTK.h" //also includes DGVAnimate
#include "DGVPlot.h"
#include "DGVPlotVTK.h"
#include "DGVVolumePlotVTK.h"

typedef vtkSmartPointer<vtkImageViewer2> ImageViewer; //!< Smart Pointers for Automated Garbage Collection
typedef vtkSmartPointer<vtkImageData> ImageData; //!< Smart Pointers for Automated Garbage Collection
typedef vtkSmartPointer<vtkImagePermute> ImagePermute; //!< Smart Pointers for Automated Garbage Collection
typedef vtkSmartPointer<vtkAlgorithmOutput> ImageAlgorithmOutput; //!< Smart Pointers for Automated Garbage Collection

/*!
    \class DGVImageVTK
    \brief This class represents the DGV Image Display object using VTK.
    \author Shekhar S. Chandra, 2008-2009

    The class displays image values using OpenGL via the VTK library. The rendering is encapsulated within
    a QVTK widget.
    Controls:
        - Left Mouse (hold): adjust the colour level.
        - Wheel: zoom the camera.
        - Middle Mouse (hold): translate image.
        - Right Mouse: context menu and zoom toggle.
        - Keypress f: fly to the picked point.
        - Keypress Shift+r: reset the camera view along the current view direction. Centers the actors and moves the camera so that all actors are visible.
        - Keypress r: reset the colour level to defaults.

    Usage Example:
    \code
    DGVImageVTK *image = new DGVImageVTK;

    image->setName(imgName);
    image->setData(newData);
    image->generateImage();
    image->show();
    \endcode
*/
class DGV_VTK_EXPORT DGVImageVTK : public QVTKWidget
{
	Q_OBJECT

public:
    /*!
        \fn DGVImageVTK::DGVImageVTK(QWidget *parent = 0)
        \brief The standard constructor
    */
	DGVImageVTK(QWidget *parent = 0);
	/*!
        \fn DGVImageVTK::DGVImageVTK(QVector<QMenu*> &menus, QWidget *parent = 0)
        \brief The overloaded constructor to take and setup extra (pre-connected) conext menus.
    */
	DGVImageVTK(QVector<QMenu*> &menus, QWidget *parent = 0);
	/*!
        \fn DGVImageVTK::~DGVImageVTK()
        \brief The standard destructor
    */
	~DGVImageVTK();

    /*!
        \fn DGVImageVTK::setName(QString filename)
        \brief Set the name of the image.
    */
    void setName(QString filename);
    /*!
        \fn DGVImageVTK::openImage(QString filename)
        \brief Opens image with given filename and stores data internally ready to be displayed.

        Currently determines image format by file extension. It calls the relevant function to open
        the image format of the file.
    */
	bool openImage(QString filename);
	/*!
        \fn DGVImageVTK::saveImage(QString filename)
        \brief Saves image with given filename, automatically identifying format from extension.

        Currently determines image format by file extension. It calls the relevant function to write
        the image format of the file.
    */
	bool saveImage(QString filename);
	/*!
        \fn DGVImageVTK::openStack(QString filename)
        \brief Opens an image stack with given filename and stores data internally ready to be displayed.

        Currently determines image format by file extension. It calls the relevant function to open
        the image format of the stack.
    */
	bool openStack(QString filename);
	/*!
        \fn DGVImageVTK::saveStack(QString filename)
        \brief Saves images with given file prefix, automatically identifying format from extension.

        Currently determines image format by file extension. It calls the relevant function to write
        the image format of the file.
    */
    bool saveStack(QString filename);
	/*!
        \fn DGVImageVTK::openPNG()
        \brief Opens image with PNG format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openPNG();
	/*!
        \fn DGVImageVTK::savePNG(const QString filename)
        \brief Saves image with PNG format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool savePNG(const QString filename);
	/*!
        \fn DGVImageVTK::openPNGVolume()
        \brief Opens image stack with PNG format with stored filename. Volume will be read with the start and end values asked. Generally, use openStack() member instead unless the format is known.
    */
	bool openPNGVolume();
	/*!
        \fn DGVImageVTK::savePNGVolume(const QString filename)
        \brief Saves image stack with PNG format with file prefix and pattern provided. Generally, use saveStack() member instead unless the format is known.
    */
	bool savePNGVolume(const QString filename);
	/*!
        \fn DGVImageVTK::openJPEG()
        \brief Opens image with JPEG format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openJPEG();
	/*!
        \fn DGVImageVTK::saveJPEG(const QString filename)
        \brief Saves image with JPEG format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveJPEG(const QString filename);
	/*!
        \fn DGVImageVTK::openJPEGVolume()
        \brief Opens image stack with JPEG format with stored filename. Volume will be read with the start and end values asked. Generally, use openStack() member instead unless the format is known.
    */
	bool openJPEGVolume();
	/*!
        \fn DGVImageVTK::saveJPEGVolume(const QString filename)
        \brief Saves image stack with JPEG format with file prefix and pattern provided. Generally, use saveStack() member instead unless the format is known.
    */
	bool saveJPEGVolume(const QString filename);
	/*!
        \fn DGVImageVTK::openTIFF()
        \brief Opens image with TIFF format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openTIFF();
	/*!
        \fn DGVImageVTK::saveTIFF(const QString filename)
        \brief Saves image with TIFF format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveTIFF(const QString filename);
	/*!
        \fn DGVImageVTK::openTIFFVolume()
        \brief Opens image stack with TIFF format with stored filename. Volume will be read with the start and end values asked. Generally, use openStack() member instead unless the format is known.
    */
	bool openTIFFVolume();
	/*!
        \fn DGVImageVTK::saveTIFFVolume(const QString filename)
        \brief Saves image stack with TIFF format with file prefix and pattern provided. Generally, use saveStack() member instead unless the format is known.
    */
	bool saveTIFFVolume(const QString filename);
	/*!
        \fn DGVImageVTK::openPNM()
        \brief Opens image with PNM (portable anymap), PBM, PGM and PPM format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openPNM();
	/*!
        \fn DGVImageVTK::savePNM(const QString filename)
        \brief Saves image with PNM (portable anymap), PBM, PGM and PPM format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool savePNM(const QString filename);
	/*!
        \fn DGVImageVTK::openPNMVolume()
        \brief Opens image stack with PNM, PGM etc. format with stored filename. Volume will be read with the start and end values asked. Generally, use openStack() member instead unless the format is known.
    */
	bool openPNMVolume();
	/*!
        \fn DGVImageVTK::savePNMVolume(const QString filename)
        \brief Saves image stack with PNM format with file prefix and pattern provided. Generally, use saveStack() member instead unless the format is known.
    */
	bool savePNMVolume(const QString filename);
	/*!
        \fn DGVImageVTK::openBMP()
        \brief Opens image with Bitmap (BMP) format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openBMP();
	/*!
        \fn DGVImageVTK::saveBMP(const QString filename)
        \brief Saves image with Bitmap (BMP) format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveBMP(const QString filename);
	/*!
        \fn DGVImageVTK::openBMPVolume()
        \brief Opens image stack with BMP format with stored filename. Volume will be read with the start and end values asked. Generally, use openStack() member instead unless the format is known.
    */
	bool openBMPVolume();
	/*!
        \fn DGVImageVTK::saveBMPVolume(const QString filename)
        \brief Saves image stack with BMP format with file prefix and pattern provided. Generally, use saveStack() member instead unless the format is known.
    */
	bool saveBMPVolume(const QString filename);
	/*!
        \fn DGVImageVTK::savePS(const QString filename)
        \brief Saves image with Post Script (PS) format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool savePS(const QString filename);
	/*!
        \fn DGVImageVTK::openDICOM()
        \brief Opens image with DICOM medical format with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openDICOM();
	/*!
        \fn DGVImageVTK::saveDICOM(const QString filename)
        \brief Saves image as DICOM medical format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveDICOM(const QString filename);
	/*!
        \fn DGVImageVTK::openVTI()
        \brief Opens VTK Image XML (VTI) File with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openVTI();
	/*!
        \fn DGVImageVTK::saveVTI(const QString filename)
        \brief Saves image with VTK XML Image (VTI) format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveVTI(const QString filename);
	/*!
        \fn DGVImageVTK::openVTK()
        \brief Opens VTK Structured Points (VTK) Legacy File with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openVTK();
	/*!
        \fn DGVImageVTK::saveVTK(const QString filename)
        \brief Saves image with VTK Structured Points (VTK) Legacy File format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveVTK(const QString filename);
    /*!
        \fn DGVImageVTK::openTGA()
        \brief Opens Targa (TGA) image File with stored filename. Generally, use openImage() member instead unless the format is known.
    */
	bool openTGA();
	/*!
        \fn DGVImageVTK::saveTGA(const QString filename)
        \brief Saves image with Targa (TGA) format with stored filename. Generally, use saveImage() member instead unless the format is known.
    */
	bool saveTGA(const QString filename);
	/*!
        \fn DGVImageVTK::complexValuedMode(bool complexValues)
        \brief Enable the maintaining of complex values and its display?
    */
	void complexValuedMode(bool complexValues);
	/*!
        \fn DGVImageVTK::isComplexValued()
        \brief Is the image complex valued?
    */
	inline bool isComplexValued()
	{   return complexData; }
	/*!
        \fn DGVImageVTK::setData(Array<imageType,2> &data)
        \brief Assigns the array data to image. You will need to call generate image after this.
    */
	void setData(Array<imageType,2> &data);
	/*!
        \fn DGVImageVTK::setData(Array<imageType,3> &data)
        \brief Assigns the 3D array data to image. You will need to call generate image after this.
        \todo Bug: Doesn't let the Volume plot (when generated) inherit parent properly. Bypass bug by using the disableVolumeDisplay() member.
    */
	void setData(Array<imageType,3> &data);
	/*!
        \fn DGVImageVTK::setData(Array<complex<imageType>,3> &data)
        \brief Assigns the complex 3D array data to image. You will need to call generate image after this. Volume display will only show absolute magnitude.
        \todo Bug: Doesn't let the Volume plot (when generated) inherit parent properly. Bypass bug by using the disableVolumeDisplay() member.
    */
	void setData(Array<complex<imageType>,3> &data);
	/*!
        \fn DGVImageVTK::setData(Array< complex<imageType>,2 > &data)
        \brief Assigns the array data to image. You will need to call generate image after this.
    */
	void setData(Array< complex<imageType>,2 > &data);
	/*!
        \fn DGVImageVTK::setData(vtkImageData *newData)
        \brief Assigns the VTK array data to image. You will need to call generate image after this.
    */
	void setData(vtkImageData *newData);
	/*!
        \fn DGVImageVTK::setDataSize(int rows, int cols)
        \brief Presizes the image data to given size. Useful for when storing results of transforms.
        Note: Call complexValuedMode if data is going to be complex. Array is initialized in the process.
    */
	void setDataSize(int rows, int cols);
	/*!
        \fn DGVImageVTK::SetInput(vtkImageData *newData)
        \brief VTK interface function: Assigns the array data to image. Same as setData() function.
    */
	void SetInput(vtkImageData *newData);
	/*!
        \fn DGVImageVTK::absoluteMagnitudeAct()
        \brief View the magnitude of the image data
    */
    inline void viewMagnitude()
    {   absoluteMagnitudeAct->setChecked(true); refresh();  }
    /*!
        \fn DGVImageVTK::viewImaginaryPart()
        \brief View the imaginary part of the image data
    */
    inline void viewImaginaryPart()
    {   imaginaryPartAct->setChecked(true); refresh();  }
    /*!
        \fn DGVImageVTK::viewRealPart()
        \brief View the real part of the image data
    */
    inline void viewRealPart()
    {   realPartAct->setChecked(true);  refresh();  }
    /*!
        \fn DGVImageVTK::viewPhase()
        \brief View the phase of the image data
    */
    inline void viewPhase()
    {   phaseAct->setChecked(true);  refresh();  }
    /*!
        \fn DGVImageVTK::data()
        \brief Returns a Blitz++ array containing the image data.
    */
	Array<imageType,2>& data();
	/*!
        \fn DGVImageVTK::dataComplex()
        \brief Returns a Complex Valued Blitz++ array containing the image data.
    */
	Array< complex<imageType>,2 >& dataComplex();
	/*!
        \fn DGVImageVTK::dataViewing()
        \brief Returns a Blitz++ array containing the image data currently being display.
        For complex based images, the relevant part being viewed is returned. If not is complex valued mode
        this behaves like the data() member.
    */
	Array<imageType,2>& dataViewing();
	/*!
        \fn DGVImageVTK::GetOutputPort()
        \brief VTK interface function: Returns the output port of the image data that can be used to pass reference to the data to VTK objects.
    */
	inline vtkAlgorithmOutput* GetOutputPort()
	{   return outputPort;  }
	/*!
        \fn DGVImageVTK::GetOutput()
        \brief VTK interface function: Returns the output of the image data that can be used to pass the actual data to VTK objects.
    */
	inline vtkImageData* GetOutput()
	{   return imageData;  }
	/*!
        \fn DGVImageVTK::isVolume()
        \brief Returns true if image is a volume.
    */
	inline bool isVolume()
	{   return volume;  }
	/*!
        \fn DGVImageVTK::disableVolumeDisplay(bool disable)
        \brief Disable the use of volumes for 3D image data. Useful if you only want to view slices.
        Call before generateImage() member.
    */
	inline void disableVolumeDisplay(bool disable)
	{   enableVolumes = !disable;  }
	/*!
        \fn DGVImageVTK::getVolume()
        \brief Returns a volume plot object if the image is a volume. Use isVolume() to check first.
    */
	DGVVolumePlotVTK* getVolume();

	/*!
        \fn DGVImageVTK::strippedName()
        \brief Returns the stripped (path removed) name of the image.
	*/
	QString strippedName();
	/*!
        \fn DGVImageVTK::strippedNamePrefix()
        \brief Returns the stripped (path removed) name of the image with "Image" prefix.
	*/
	QString strippedNamePrefix();
	/*!
        \fn DGVImageVTK::addToContextMenu(QVector<QMenu*> &menus)
        \brief Adds the menu to the context menu. Connections are assumed to be made before hand.
	*/
	void addToContextMenu(QVector<QMenu*> &menus);
    /*!
        \fn DGVImageVTK::setConsole(DGVConsole *newConsole)
        \brief Assigns a console for message output. You should set this before calling data members to ensure
        messages reach the console (if one is present).
	*/
	void setConsole(DGVConsole *newConsole);
	/*!
        \fn DGVImageVTK::setVerboseMode(bool verbose)
        \brief Verbose mode for message output.
	*/
	inline void setVerboseMode(bool verbose)
	{   verboseMode = verbose;  }
	/*!
        \fn DGVImageVTK::alignImages(bool align)
        \brief Rotate images by 90 degrees to compensate for different image indexing.
	*/
	inline void alignImages(bool align)
	{   Blitz.alignmentForImages(align);  }
	/*!
        \fn DGVImageVTK::getMaxValue()
        \brief Returns the maximum value of the image data. If the array has not loaded, it will trigger a loading of the array.
	*/
	imageType getMaxValue();
	/*!
        \fn DGVImageVTK::getMinValue()
        \brief Returns the minimum value of the image data. If the array has not loaded, it will trigger a loading of the array.
	*/
	imageType getMinValue();
	/*!
        \fn DGVImageVTK::getMean()
        \brief Returns the mean/average of the image data. If the array has not loaded, it will trigger a loading of the array.
	*/
	imageType getMean();

public slots:
    /*!
        \fn DGVImageVTK::table()
        \brief Sets up table of the image data.
    */
    void table();
    /*!
        \fn DGVImageVTK::mergedSurfacePlot()
        \brief Sets up a surface plot of the image data merged with the image data.
    */
    void mergedSurfacePlot();
    /*!
        \fn DGVImageVTK::generateVolume()
        \brief Assigns the image data volume to a volume display.

        If both complex and a volume, only the absolute magnitude will be shown in the volume plot.
    */
	void generateVolume();
	/*!
        \fn DGVImageVTK::generateImage()
        \brief Assigns the array data to the image.

        If complex, viewing options are available through the context menu. If a 3D volume, a volume plot will also be generated if enabled.
        If both complex and a volume, only the absolute magnitude will be shown in the volume plot.
    */
	void generateImage();
	/*!
        \fn DGVImageVTK::scan()
        \brief Animates the image data volume per slice.
    */
	void scan();
    /*!
        \fn DGVImageVTK::clip()
        \brief Clips the image data.
    */
    void clip();
    /*!
        \fn DGVImageVTK::histogram()
        \brief Determine and display histogram from image.
    */
    void histogram();
    /*!
        \fn DGVImageVTK::saveImage()
        \brief Saves image after asking for the filename, automatically identifying format from extension.

        Currently determines image format by file extension. It calls the relevant function to write
        the image format of the file. Overloaded member that asks for the filename.
    */
	bool saveImage();
	/*!
        \fn DGVImageVTK::saveStack()
        \brief Saves image with given file prefix after asking for the filename, automatically identifying format from extension.

        Currently determines image format by file extension. It calls the relevant function to write
        the image format of the file. Overloaded member that asks for the filename.
    */
	bool saveStack();
    /*!
        \fn DGVImageVTK::refresh()
        \brief Sets up table of the image data.
    */
    void refresh();
    /*!
        \fn DGVImageVTK::renameData()
        \brief Renames the image data.
    */
    void renameData();
    /*!
        \fn DGVImageVTK::updateData(int row, int col)
        \brief Updates image values to match table.
    */
    void updateData(int row, int col);
    /*!
        \fn DGVImageVTK::interpolateDisplay()
        \brief Toggles interpolation.
    */
    void interpolateDisplay();
    /*!
        \fn DGVImageVTK::meanGreyScale()
        \brief Sets colour level to mean of the data.
    */
    void meanGreyScale();
    /*!
        \fn DGVImageVTK::incrementSlice()
        \brief Go up in the slices.
    */
    void incrementSlice();
    /*!
        \fn DGVImageVTK::decrementSlice()
        \brief Go down in the slices.
    */
    void decrementSlice();
    /*!
        \fn DGVImageVTK::viewToXYPlane()
        \brief Change view to xy-plane.
    */
    void viewToXYPlane();
    /*!
        \fn DGVImageVTK::viewToZXPlane()
        \brief Change view to zx-plane.
    */
    void viewToZXPlane();
    /*!
        \fn DGVImageVTK::viewToZYPlane()
        \brief Change view to zy-plane.
    */
    void viewToZYPlane();

signals:
    /*!
        \fn DGVImageVTK::resultAvailable(DGVImageVTK *)
        \brief Send signal that Result is available for showing.
    */
    void resultAvailable(DGVImageVTK *);
    /*!
        \fn DGVImageVTK::tableAvailable(DGVTableVTK *tableWidget)
        \brief Send signal that a table is available for showing.
    */
    void tableAvailable(DGVTableVTK *tableWidget);
    /*!
        \fn DGVImageVTK::surfacePlotAvailable(DGVSurfacePlotVTK *plotWidget)
        \brief Send signal that a surface plot is available for showing.
    */
    void surfacePlotAvailable(DGVSurfacePlotVTK *plotWidget);
    /*!
        \fn DGVImageVTK::plotAvailable(DGVPlot *plotWidget)
        \brief Send signal that a plot is available for showing.
    */
    void plotAvailable(DGVPlot *plotWidget);
    /*!
        \fn DGVImageVTK::plotAvailable(DGVPlotVTK *plotWidget)
        \brief Send signal that a plot is available for showing.
    */
    void plotAvailable(DGVPlotVTK *plotWidget);
    /*!
        \fn DGVImageVTK::volumePlotAvailable(DGVVolumePlotVTK *plotWidget)
        \brief Send signal that a surface plot is available for showing.
    */
    void volumePlotAvailable(DGVVolumePlotVTK *plotWidget);
    /*!
        \fn DGVImageVTK::recentFileAvailable(const QString &fileName)
        \brief Send signal that a recent filename is available for saving.
    */
    void recentFileAvailable(const QString &fileName);
    /*!
        \fn DGVImageVTK::nameChanged(const QString newName)
        \brief Send signal that the window has been renamed.
    */
    void nameChanged(const QString newName);

protected:
	QString name; //!< Name of the Image
	bool loaded; //!< Loaded Image from file?
	bool arrayLoaded; //!< To avoid loading unnecessarily into Blitz array
	bool imageDataSource; //!< Source is VTK ImageData?
	bool imageDataLoaded; //!< To avoid loading VTK ImageData unnecessarily
	bool externalData; //!< Using external data?
	bool viewing; //!< Viewer setup?
	bool volume; //!< 3D data is maintained?
	bool complexData; //!< Complex data maintained?
	bool consoleAssigned; //!< Message Console
	bool verboseMode; //!< Verbose message output mode
	bool enableVolumes; //!< Enable the use of volume displays in 3D datasets?
	bool permuted; //!< Has the volume been permuted?
	int sliceInView; //!< Slice currently in view

	//Context Menu
	QMenu *contextMenu; //!< Context Menu
	QVector<QMenu*> menusToAdd; //!< Context Menu's to add.
	//------------------
	QAction *tableAct; //!< Action object for displaying a table of data.
	QAction *surfacePlotAct; //!< Action object for displaying a surface plot of data merged with image data.
	QAction *scanAct; //!< Action for scanning the volume
	QAction *volumeAct; //!< Action for Generating a volume
	QAction *clipAct; //!< Action for Clipping image
	QAction *histAct; //!< Action for Histogram
	//------------------
	QAction *interpolateAct; //!< Interpolate image?
	QAction *meanGreyAct; //!< Mean grey scale
	QMenu *viewMenu; //!< Context Menu
	QAction *viewXY; //!< Change view to zx-plane
	QAction *viewZX; //!< Change view to zx-plane
	QAction *viewZY; //!< Change view to zy-plane
	//------------------
	QActionGroup *complexGroup; //!< Grouping for check boxes
	QAction *absoluteMagnitudeAct; //!< Show Absolute Magnitude?
	QAction *imaginaryPartAct; //!< Show Imaginary Part?
	QAction *realPartAct; //!< Show Real Part?
	QAction *phaseAct; //!< Show phase/arg?
    //------------------
    QAction *saveAct; //!< Action object for saving an image.
    QAction *saveStackAct; //!< Action object for saving an image stack.
    QAction *refreshAct; //!< Action object for refreshing the display of an image.
    QAction *renameAct; //!< Action for renaming data
	QAction *closeAct; //!< Closes window

	ImageViewer viewer; //!< VTK Viewer handler, Smart Pointer
	ImageData imageData; //!< Raw VTK Image Data, Smart Pointer
	vtkImageMagnify *magnify; //!< Magnification and Interpolation handler, manually deleted
	ImagePermute permute; //!< Permute axis class, Smart Pointer
	DGVTableVTK *dataTable; //!< Table form of data.
	DGVSurfacePlotVTK *surfacePlot; //!< Surface plot of data.
	DGVVolumePlotVTK *volViewer; //!< Volume plot of data.

    DGVConsole *console; //!< Console for message output
	DGVBlitzArrayCasterVTK<imageType> Blitz; //!< For casting Blitz arrays to and from VTK structures
	Array<imageType,2> imageArray; //!< Blitz++ Array Data container. Initially of size zero.
	Array< complex<imageType>,2 > imageComplexArray; //!< Blitz Complex Array. Will be empty until called. Initially of size zero.

	ImageAlgorithmOutput outputPort; //!< VTK Output member, Smart Pointer

	double timerInterval; //!< Timer Interval for slice viewing (scanning)
	int timerId; //!< Timer Id for slice viewing (scanning)

	///Private Functions
	/*!
		\fn DGVImageVTK::createActions()
		\brief Creates SOME actions for menus
	*/
	void createActions();
	/*!
		\fn DGVImageVTK::createConnections()
		\brief Creates all the connections for the Qt GUI
	*/
	void createConnections();
	/*!
		\fn DGVImageVTK::connectTable(DGVTableVTK *child)
		\brief Connects the spawned tables to any data changes.
	*/
	void connectTable(DGVTableVTK *child);
	/*!
		\fn DGVImageVTK::dataToArray()
		\brief Converts the VTK data to a Blitz array which is stored internally. This is used by the data() function to return the array.
	*/
	void dataToArray();
	/*!
		\fn DGVImageVTK::sliceToData()
		\brief Loads the new slice into array (if slice is changed).
	*/
	bool sliceToData();
	/*!
		\fn DGVImageVTK::arrayToData()
		\brief Converts the Blitz array to VTK data which is stored internally. This is used by the setData() function to assign the data.
	*/
	void arrayToData();
	/*!
		\fn DGVImageVTK::checkDataIsManual()
		\brief Is there image data present by bypassing setData()? If so then tag as image loaded so image can be generated and displayed.
	*/
	void checkDataIsManual();
	/*!
		\fn DGVImageVTK::setupEvents()
		\brief Executes common events setup code.
	*/
	void setupEvents();
	/*!
		\fn DGVImageVTK::setupViewerFromReader()
		\brief Executes common code to setup a viewer after a reader has read data from file.
	*/
	void setupViewerFromReader();
	/*!
		\fn DGVImageVTK::addContextMenuExtras()
		\brief Adds extra parts to context menu. Assumes call is always made inside contextMenuEvent().
	*/
	void addContextMenuExtras();
	/*!
		\fn DGVImageVTK::contextMenuEvent(QContextMenuEvent *event)
		\brief The context menu setup member
	*/
	void contextMenuEvent(QContextMenuEvent *event);
	/*!
		\fn DGVImageVTK::timerEvent(QTimerEvent *event)
		\brief The timer events handler
	*/
	virtual void timerEvent(QTimerEvent *event);
	/*!
		\fn DGVImageVTK::keyPressEvent(QKeyEvent *event)
		\brief Control and interpret key inputs from user. Intercepts key presses before VTK Interactor. If key press
		is not supported then passed to VTK interactor. This has been removed because of its conflict with VTK.
	*/
	//void keyPressEvent(QKeyEvent *event);
	/*!
        \fn DGVImageVTK::printError(QString msg)
        \brief Error message wrapper for console.
	*/
	void printError(QString msg);
	/*!
        \fn DGVImageVTK::printWarning(QString msg)
        \brief Warning message wrapper for console.
	*/
	void printWarning(QString msg);
	/*!
        \fn DGVImageVTK::printInfo(QString msg)
        \brief Info message wrapper for console.
	*/
	void printInfo(QString msg);
};

#endif

///\fn handleKeys(vtkObject* obj, unsigned long, void *clientData, void *callData)
///\brief Function for binding keyboard VTK events without derived classes.
static void handleKeys(vtkObject* obj, unsigned long, void *clientData, void *callData);
///\fn handleWheelUp(vtkObject* obj, unsigned long, void *clientData, void *callData)
///\brief Function for binding the mouse wheel up VTK events without derived classes.
static void handleWheelUp(vtkObject* obj, unsigned long, void *clientData, void *callData);
///\fn handleWheelDown(vtkObject* obj, unsigned long, void *clientData, void *callData)
///\brief Function for binding the mouse wheel down VTK events without derived classes.
static void handleWheelDown(vtkObject* obj, unsigned long, void *clientData, void *callData);
